package com.zx.onlineeducation.service.edu.controller.front;

import com.zx.onlineeducation.common.util.R;
import com.zx.onlineeducation.service.edu.entity.CourseDO;
import com.zx.onlineeducation.service.edu.entity.TeacherDO;
import com.zx.onlineeducation.service.edu.service.CourseService;
import com.zx.onlineeducation.service.edu.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 首页 前台 前端控制器
 * </p>
 *
 * @author 郑雪
 * @since 2022-01-25
 */
@Api(tags = "首页前台接口")
@RestController
@RequestMapping("/edu/index/front")
@CrossOrigin // 解决跨域
public class IndexFrontController {

    /**
     * 课程服务接口
     */
    @Autowired
    private CourseService courseService;

    /**
     * 讲师服务接口
     */
    @Autowired
    private TeacherService teacherService;

    @ApiOperation("获取首页热门课程和名师列表")
    @GetMapping("/course/and/teacher")
    public R getCourseAndTeacherList(
            @ApiParam(value = "热门课程显示条数，默认为8条")
            @RequestParam(value = "courseLimit", required = false, defaultValue = "8") Integer courseLimit,
            @ApiParam(value = "名师显示条数，默认为4条")
            @RequestParam(value = "teacherLimit", required = false, defaultValue = "4") Integer teacherLimit) {
        // 获取热门课程数据列表
        List<CourseDO> courseList = courseService.getHotCourseList(courseLimit);
        // 获取名师数据列表
        List<TeacherDO> teacherList = teacherService.getFamousTeacherList(teacherLimit);
        // 返回结果
        return R.ok().data("courseList", courseList).data("teacherList", teacherList);
    }

}

